package com.mlh.furn.bean;

import org.hibernate.validator.constraints.Range;
import org.springframework.util.StringUtils;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;

public class Furn {
    //默认图片地址
    private String imgPath="assets/images/product-image/1.jpg";

    //构造全参构造器
    public Furn(Integer id, String name, String maker, BigDecimal price, Integer sales, Integer stock, String imgPath) {
        this.id = id;
        this.name = name;
        this.maker = maker;
        this.price = price;
        this.sales = sales;
        this.stock = stock;
        //修改 Furn.java , 当创建 Furn 对象 imgPath 为 null 时, imgPath 给默认值
        //imgPath != null && || imgPath. equals("") =>使用一个工具类方法完成
        //if(!(imgPath == null || imgPath.equals("")) ){
        //    this.imgPath = imgPath;
        //}
        /*  public static boolean hasText(@Nullable String str) {
            return (str != null && !str.isEmpty() && containsText(str));
        }*/
        //StringUtils.hasText():如果字符序列不为 null 值,并且不含有空白字符序列，并且字符序列的长度大于 0 ,则返回 true
        // if(StringUtils.hasText(imgPath)){
        //     this.imgPath=imgPathDefault;
        // }else{
        //     this.imgPath=imgPathDefault;
        // }
        if(!(imgPath == null || imgPath.equals("")) ){
            this.imgPath = imgPath;
        }
    }

    //声明无参构造器
    public Furn(){}

    //重写toString方法
    @Override
    public String toString() {
        return "Furn{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", maker='" + maker + '\'' +
                ", price=" + price +
                ", sales=" + sales +
                ", stock=" + stock +
                ", imgPath='" + imgPath + '\'' +
                '}';
    }

    private Integer id;
    @NotEmpty(message = "请输入家具名")
    private String name;
    @NotEmpty(message = "请输入制造厂商")
    private String maker;
    @NotNull(message = "请输入数字")
    @Range(min = 0,message ="价格不能小于0")
    private BigDecimal price;
    @NotNull(message = "请输入销售数量")
    @Range(min = 0,message = "销售数量不能小于0")
    private Integer sales;
    @NotNull(message = "请输入库存数量")
    @Range(min = 0,message = "库存数量不能小于0")
    private Integer stock;


    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    public String getMaker() {
        return maker;
    }

    public void setMaker(String maker) {
        this.maker = maker == null ? null : maker.trim();
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public Integer getSales() {
        return sales;
    }

    public void setSales(Integer sales) {
        this.sales = sales;
    }

    public Integer getStock() {
        return stock;
    }

    public void setStock(Integer stock) {
        this.stock = stock;
    }

    public String getImgPath() {
        return imgPath;
    }

    public void setImgPath(String imgPath) {
        this.imgPath = imgPath == null ? null : imgPath.trim();
    }
}